在 kubernetes 中,主要的狀態儲存在 control plane 的 etcd 中。
另外若是要從乾淨的環境中恢復 kubernetes 集群,也要保留原本的 certificate,才能重新建立集群內安全連線。
備份步驟如下:
完整指令如下:
ETCDIMAGE=k8s.gcr.io/etcd:3.3.10
ssh master1 "docker run --rm \
-v \$(pwd):/backup \
--network host \
-v /etc/kubernetes/pki/etcd:/etc/kubernetes/pki/etcd \
--env ETCDCTL_API=3 \
${ETCDIMAGE} \
etcdctl \
--endpoints=https://127.0.0.1:2379 \
--cacert=/etc/kubernetes/pki/etcd/ca.crt \
--cert=/etc/kubernetes/pki/etcd/healthcheck-client.crt \
--key=/etc/kubernetes/pki/etcd/healthcheck-client.key \
snapshot save /backup/etcd-snapshot-latest.db"
ssh master1 "sudo tar -zcpf - -C /etc/kubernetes/pki ." | cat > kubepki.tgz
ssh master1 "tar -zcf - etcd-snapshot-latest.db" | cat > etcd-snapshot-latest.tgz
ssh master1 "rm etcd-snapshot-latest.db"